package com.sc.nft.admin.rpc;

import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.entity.UserWallet;
import com.sc.nft.entity.dto.DepositRefundDTO;
import com.sc.nft.entity.dto.MarginPaymentDTO;
import com.sc.nft.entity.vo.DepositRefundVO;
import com.sc.nft.entity.vo.MarginPaymentVO;
import com.sc.nft.exception.GlobalRunTimeException;
import com.sc.nft.pool.UserPool;
import com.sc.nft.service.UserWalletService;
import com.sc.nft.sup.Result;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/rpc/userWallet")
public class UserWalletRpc {

    private final UserWalletService userWalletService;

    @PostMapping(value = "/getTheUserWalletDataThroughTheUserIdRpc", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "用户钱包", notes = "用户钱包", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiIgnore
    public Result<UserWallet> getTheUserWalletDataThroughTheUserIdFeign(@RequestBody IdRequest idRequest) {
        UserWallet byUserId = userWalletService.getByUserId(idRequest.getId());
        return Result.success(byUserId);
    }

    @PostMapping(value = "/marginPayment", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "保证金支付", notes = "保证金支付", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiIgnore
    public Result<MarginPaymentVO> marginPayment(@RequestBody MarginPaymentDTO marginPaymentDTO) {

        MarginPaymentVO marginPaymentVO = userWalletService.marginPayment(marginPaymentDTO);
        return Result.success(marginPaymentVO);
    }

    @PostMapping(value = "/depositRefund", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "保证金退还", notes = "保证金退还", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiIgnore
    public Result<DepositRefundVO> depositRefund(@RequestBody DepositRefundDTO depositRefundDTO) {
        DepositRefundVO depositRefundVO = userWalletService.depositRefund(depositRefundDTO);
        return Result.success(depositRefundVO);
    }

}
